#define _CRT_SECURE_NO_WARNINGS   1

#include<iostream>
#include<vector>
#include<stack>

#define N 5
using namespace std;

class Solution {
public:
	bool IsPopOrder(vector<int> pushV, vector<int> popV)
	{
		int len = pushV.size();
		stack<int> s;
		int n = 0;
		for (int i = 0; i < len; i++)
		{
			while (n < len && (s.empty() || s.top() != popV[i]))
			{
				s.push(pushV[n]);
				n++;
			}
			if (s.top() == popV[i])
				s.pop();
			else
				return false;
		}
		return true;

	}
};

int main()
{
	Solution Sol;
	vector<int>pushV;
	vector<int>popV;
	int num;
	for (int i = 0; i < N; i++)
	{
		cin >> num;
		pushV.push_back(num);
	}
	for (int i = 0; i < N; i++)
	{
		cin >> num;
		popV.push_back(num);
	}
	if (Sol.IsPopOrder(pushV, popV))
		cout << "True" << endl;
	else
		cout << "False" << endl;
	return 0;
}